/*******************************************************************************
+
+  LEDA 6.3  
+
+
+  windows.c
+
+
+  Copyright (c) 1995-2010
+  by Algorithmic Solutions Software GmbH
+  All rights reserved.
+ 
*******************************************************************************/

#include "StdAfx.h"
#include <LEDA/graphics/window.h>
#include <LEDA/graphics/bitmaps/button32.h>
#include <LEDA/core/string.h>
#include <LEDA/graphics/geowin.h>
#include <LEDA/geo/rectangle.h>
#include <LEDA/geo/circle.h>
#include <LEDA/geo/rat_rectangle.h>
using namespace leda;
#if defined(LEDA_STD_IO_HEADERS)
using std::cout;
using std::cin;
using std::endl;
#endif
int type = 0;
panel_item pQuality;
int my_event_handler(window* wp, int e, int val, double x, double y, 
                                                            unsigned long t)
{ 
  if (e == button_press_event || e == button_release_event)
     cout << e << " " << val << " " << x << " " << y << " " << t << endl;

  return no_event; // read_mouse will not terminate
}
void drawMarix(window& m,double x,double y)
{
	m.draw_edge(x-5,y,x,y+5);
	m.draw_edge(x,y+5,x+5,y);
	m.draw_edge(x+5,y,x,y-5);
	m.draw_edge(x,y-5,x-5,y);
	m.set_mode(xor_mode);
	m.draw_text(x-3,y+2,"hello",window::fgcol); 
}
class style_action : public window_handler {
public:
  void operator()() 
  { 
	  int n =get_int(); 
	  if(n == 50)
		{
		window m(500,300,"MATRIX M");
		m.display(window::min,window::center);
		m.draw_circle(10,10,10,orange);
		m.draw_rectangle(10,10,20,20);
		m.draw_edge(10,10,20,20,window::fgcol);
		m.draw_filled_rectangle(20,20,40,40,window::fgcol);
		drawMarix(m,50,50);
		window s(500,300,"MATRIX S");
		s.display(window::max,window::center);
		s.draw_circle(10,10,10,orange);
		s.draw_rectangle(10,10,20,20);
		 window* w;
		 double  x,y;
		 point   p;
		// w1.read_mouse();
   while(read_mouse(w,x,y) != MOUSE_BUTTON(3))  
   { 
     if (w == &m) // draw points
     {
		 put_back_event();
          m >> p;
         // w1.draw_point(p,blue);
		 // w1.draw_disc(x,y,0.8,blue);
         continue;
      }
	
    }
		}
  }
};
class choice_action : public window_handler {
public:
  void operator()() 
  { 
	  int n =get_int(); 
	  window* w = get_window_ptr();
	  
	  if(n==0)
		  type = 0;
	  else if (n==1)
		  type = 1;
	  else if (n==2)
		  type = 2;
  }
};

int main()
{
	bool B=true;
	string s0="matrix(1,2)*matrix(2,3)*matrix(3,4)";
	string s1="0";
	string s="";
	style_action   but_action;
	choice_action   choice_handler;
	list<string> CML;
    CML.append("1"); CML.append("2");
    CML.append("3"); CML.append("4");CML.append("5");CML.append("6");CML.append("7");CML.append("8");CML.append("9");
	CML.append("10");CML.append("11");CML.append("12");CML.append("13");CML.append("14");CML.append("15");CML.append("16");
	CML.append("17");CML.append("18");CML.append("19");CML.append("20");CML.append("21");CML.append("22");CML.append("23");
	CML.append("24");CML.append("25");CML.append("26");
  list<string> CML1;
  CML1.append("1..5"); CML1.append("1..10"); CML1.append("1..15");
  CML1.append("1..20"); CML1.append("1..25");CML1.append("1..50");CML1.append("1..100");
  list<string> choice_option;
  choice_option.append("User define with matrix dimensions and values");
  choice_option.append("User define with matrix dimensions only");
  choice_option.append("Random");
    window w1(1024,250,"MATRIX CHAIN ORDER");
	w1.init(-100,+100,-100);
   //w1.set_bg_color(yellow);
   //w1.set_show_coordinates(true);
   //w1.bool_item("User define with matrix dimensions and values",B);
   //w1.string_item("",s);
   //w1.bool_item("User define with matrix dimensions only",B);
   //w1.string_item("",s);
   //w1.bool_item("Random",B);
   //w1.text_item("");
   int c=3;
   w1.choice_item("",c,choice_option,choice_handler);
   
   pQuality = w1.string_item("Quantity",s1,CML,8);
   
   w1.string_item("Dimension",s1,CML1,8);
   w1.string_item("Matrix Input",s0);
  // w1.text_item("");w1.text_item("");
   w1.button("Compute", 50, but_action);
  // w1.button(string("Compute",1));
   w1.text_item("");
   w1.string_item("Sequence Of Dimensions",s);
   w1.string_item("Optimal Parenthesization",s);
   w1.string_item("Left To Right Scalar Multiplication",s);
   w1.string_item("Optimized Scalar Multiplication",s);
   w1.display(window::center,window::center);
    w1.draw_hline(0); 
    w1.draw_vline(0);
   double  x,y;
   point   p;
   window* w;

  // w1.read_mouse();
   while(read_mouse(w,x,y) != MOUSE_BUTTON(3))  
   { 
     if (w == &w1) // draw points
     {
		 put_back_event();
          w1 >> p;
         continue;
      }
    }

   return 0;
}

/*
#include "StdAfx.h"
#include <LEDA/graphics/window.h>
#include <LEDA/graphics/bitmaps/button32.h>
#include <LEDA/core/string.h>
#include <LEDA/graphics/geowin.h>
#include <LEDA/geo/rectangle.h>
#include <LEDA/geo/circle.h>
#include <LEDA/geo/rat_rectangle.h>
using namespace leda;
#if defined(LEDA_STD_IO_HEADERS)
using std::cout;
using std::cin;
using std::endl;
#endif
#include <LEDA/core/list.h>
#include <LEDA/geo/point.h>
#include <LEDA/graph/graph.h>
#include <LEDA/graphics/window.h>
//#include <LEDA/geo/geo_alg.h>



int main()
{
  int height=600, width=500;
  window W(width,height,"Demo of Using Window");

  int xmin=-1000, xmax=1000, ymin=-1000;
  W.init(xmin,xmax,ymin);
  
  W.text_item("\\bf\\blue Please Choose an Algorithm and Press 'Run'");
  W.text_item("");
  W.text_item("The right mouse button terminates the program");
  int c=3;
  W.choice_item("",c,"Convex Hull","Triangulation","Delaunay Triangulation");
  W.text_item("");W.text_item("");
  W.button("Run");

  W.open(window::center,window::center);W.display();

  W.set_node_width(3);

  list<point> L;random_points_in_square(25,900,L);

  for (;;) {
    W.clear();

    point p; forall(p,L) W.draw_filled_node(p);

    if (c==0) {
      list<point> H=CONVEX_HULL(L);

      list_item lit;forall_items(lit,H) {
        point p=H[lit];point q=H[H.cyclic_succ(lit)];
        W.draw_edge(p,q,red);
      }
    }

    if (c==1) {
      GRAPH<point,int> T;TRIANGULATE_POINTS(L,T);

      edge e;forall_edges(e,T) { 
        point p=T[T.source(e)], q=T[T.target(e)];
        W.draw_edge(p,q,green);
      }
    }

    if (c==2)  {
      GRAPH<point,int> DT;DELAUNAY_TRIANG(L,DT);

      edge e;forall_edges(e,DT) {
        point p=DT[DT.source(e)], q=DT[DT.target(e)];
        W.draw_edge(p,q,blue);
      }
    }  

    if (W.read_mouse()==MOUSE_BUTTON(3)) break;

  }

  W.screenshot("window_demo");

  return 0;
}  
*/